package com.shg.present.controller;

import com.shg.core.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by roger on 2017/4/18.
 */
@Controller

public class LoginController {

    @RequestMapping(value="/login", method= RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> login(HttpServletRequest request, HttpServletResponse response)    {
        Map<String,Object>  map = new HashMap<>();
        String username = request.getParameter("userName");
        String password = request.getParameter("password");
        if (!username.equals("") && password != "") {
            User user = new User(username, password);
            request.getSession().setAttribute("user", user);
            map.put("result",1);
        } else {
            map.put("result",0);
        }
        return map;
    }
}
